import WithRepoBasic from '../../components/with-repo-basic'
import 'github-markdown-css'
import dynamic from 'next/dynamic'
import { request } from '../../lib/api'

const MdRenderer = dynamic(import('../../components/md-renderer'))

function Detail (readme) {
  const str = readme.readme.content

  return (
    <MdRenderer content={str} isBase64={true} />
  )
}
Detail.getInitialProps = async (ctx) => {
  const { owner, name } = ctx.query
  //const readmeRepo = await axios.get(`https://api.github.com/repos/${owner}/${name}/readme`)
  const { data } = await request({
    url: `/repos/${owner}/${name}/readme`,
  }, ctx.req, ctx.res)

  return {
    readme: data
  }
}

export default WithRepoBasic(Detail, 'index')
